package com.student.Activitys.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.student.Activitys.R;
import com.student.Activitys.utils.DataUtils;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * 项目名称：智慧校园学生端
 * 类描述：设置列数
 * 创建人：张飞祥
 * 创建时间：2017/9/27 9:30
 * 修改人：张飞祥
 * 修改时间：2017/9/27 9:30
 * 修改备注：
 */
public class ScheduleWeekDateAdapter extends BaseAdapter {

    private String[] dates;     //日期
    private String[] weeks;     //星期
    private Context context;    //上下文
    private LayoutInflater inflater = null;

    public ScheduleWeekDateAdapter( Context context,String[] dates, String[] weeks) {
        this.dates = dates;
        this.weeks = weeks;
        this.context = context;
        this.inflater= LayoutInflater.from(context);  //这里就是确定你listview在哪一个layout里面展示
    }

    @Override
    public int getCount() {
        return dates.length;
    }

    @Override
    public Object getItem(int position) {
        return dates[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_schedule_week_date, null);
            //把convertView中的控件保存到viewHolder中
            holder.number = (TextView)convertView .findViewById(R.id.item_schedule_week_number);
            holder.en = (TextView)convertView .findViewById(R.id.item_schedule_week_en);
            //通过setTag将ViewHolder与convertView绑定
            convertView.setTag(holder);
        }else{
            //通过调用缓冲视图convertView，然后就可以调用到viewHolder,viewHolder中已经绑定了各个控件，省去了findViewById的步骤
            holder = (ViewHolder)convertView.getTag();
        }

        //今天 设置红色
        if (DataUtils.getNowDate("dd").equals(dates[i])){
            holder.number.setTextColor(Color.RED);
        }
        //没课设置灰色
        if (i == 5 || i == 6){
            holder.number.setTextColor(Color.parseColor("#B3B3B3"));
        }


        //日期号
        holder.number.setText(dates[i]);
        //星期号
        holder.en.setText(weeks[i]);
        //适配
        AutoUtils.auto(convertView);
        return convertView;
    }

    static class ViewHolder
    {
        public TextView number;
        public TextView en;
    }
}
